package com.example.studentmanager.fargment;

import android.content.Intent;
import android.os.Bundle;
import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.studentmanager.R;
import com.example.studentmanager.activity.SettingActivity;
import com.example.studentmanager.db.StudentManager;
import com.example.studentmanager.db.entity.Student;

public class CenterFragment extends Fragment {
    public static CenterFragment createFragment() {
        return new CenterFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_center, container, false);
        initView(root);
        return root;
    }

    private void initView(View root) {
        Student loginStudent = StudentManager.getLoginStudent();
        TextView tvUsername = root.findViewById(R.id.tvUsername);
        tvUsername.setText("用户名：" + loginStudent.getUsername());
        TextView tvName = root.findViewById(R.id.tvName);
        tvName.setText("姓名：" + loginStudent.getName());
        TextView tvClass = root.findViewById(R.id.tvClass);
        tvClass.setText("班级：" + loginStudent.getClazz());
        TextView tvNumberId = root.findViewById(R.id.tvNumberId);
        tvNumberId.setText("学号：" + loginStudent.getNumberId());


        root.findViewById(R.id.btSetting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(), SettingActivity.class));
            }
        });

    }
}
